package com.hrm.company.service;

import com.hrm.common.utils.IdWorker;
import com.hrm.domain.company.Department;
import com.hrm.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private IdWorker idWorker;

    /**
     * 1. 保存部门
     */
    public void save(Department department) {
        // 设置主键的值
        String id = idWorker.nextId() + "";

        department.setId(id);
        department.setCreateTime(new Date());
        departmentMapper.insert(department);
    }

    /**
     * 2. 更新部门
     */
    public void update(Department department) {
        departmentMapper.updateById(department);
    }

    /**
     * 3. 根据id查询部门
     */
    public Department findById(String id) {
        return departmentMapper.selectById(id);
    }

    /**
     * 4. 查询全部部门列表
     */
    public List<Department> findAll(String companyId) {
        return departmentMapper.selectAll(companyId);
    }

    /**
     * 5. 根据id删除部门
     */
    public void deleteById(String id) {
        departmentMapper.deleteById(id);
    }
}
